package agenda;

import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Iterator;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaIncial.java
 *
 * Created on 08/11/2011, 17:54:35
 */

/**
 *
 * @author Brenno
 */
public class JanelaInicial extends javax.swing.JFrame {

    /** Creates new form JanelaIncial */
    public JanelaInicial() {
        initComponents();
        setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
        setTitle("Carpe Diem Agenda");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jFrame1 = new javax.swing.JFrame();
        JPanelInicial = new javax.swing.JPanel();
        jSeparator1 = new javax.swing.JSeparator();
        BotaoPerfil = new javax.swing.JButton();
        BotaoContato = new javax.swing.JButton();
        BotaoCadastraContatos = new javax.swing.JButton();
        CadastrarEventos = new javax.swing.JButton();
        ListaEventos = new javax.swing.JButton();
        Sobre = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableEventosDoDia = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableAniversarios = new javax.swing.JTable();
        BotaoPesquisaContatos = new javax.swing.JButton();
        BotaoPesquisaEvento = new javax.swing.JButton();
        BotaoPesquisaEvento3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabelAnivérsarios = new javax.swing.JLabel();
        jLabelEventosDeHoje = new javax.swing.JLabel();

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        JPanelInicial.setBackground(new java.awt.Color(255, 255, 255));

        jSeparator1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        BotaoPerfil.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/iconePerfil.png"))); // NOI18N
        BotaoPerfil.setToolTipText("Perfil do úsuario");
        BotaoPerfil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	new JanelaPerfil().setVisible(true);
            }
        });

        BotaoContato.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/MSN Messenger - folder - big.png"))); // NOI18N
        BotaoContato.setToolTipText("Lista de contatos");
        BotaoContato.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                new JanelaContatos().setVisible(true);
            }
        });

        BotaoCadastraContatos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/add-user-icon.png"))); // NOI18N
        BotaoCadastraContatos.setToolTipText("Cadastra contatos");
        BotaoCadastraContatos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	new JanelaCadastraContatos().setVisible(true);
            }
        });

        CadastrarEventos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/Imagem1.png"))); // NOI18N
        CadastrarEventos.setToolTipText("Cadastrar evento");
        CadastrarEventos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                new JanelaCadastrarEvento().setVisible(true);
            }
        });

        ListaEventos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/Imagem3.png"))); // NOI18N
        ListaEventos.setToolTipText("Lista de eventos");
        ListaEventos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                new JanelaEventos().setVisible(true);
            }
        });

        Sobre.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/InfoIcon.png"))); // NOI18N
        Sobre.setToolTipText("");
        Sobre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                new Sobre().setVisible(true);
            }
        });

        jTableEventosDoDia.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Data", "Horário", "Duração",
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        Calendar calendar = new GregorianCalendar();
        Iterator<Evento> it = Agenda.Eventos.iterator();
		while (it.hasNext()) {
			Evento evento = it.next();
			try{
				int dia = Integer.parseInt(evento.getData().substring(0, 2));
				int mes = Integer.parseInt(evento.getData().substring(3, 5));
				int ano = Integer.parseInt(evento.getData().substring(6, 10));
				if(dia == calendar.get(GregorianCalendar.DAY_OF_MONTH) && mes == (calendar.get(GregorianCalendar.MONTH)+1) && ano == calendar.get(GregorianCalendar.YEAR)){
					DefaultTableModel modelo = (DefaultTableModel) jTableEventosDoDia.getModel();
					modelo.addRow(new String[]{evento.getNome(),evento.getData(),evento.getHorario(),evento.getDuracao()});
				}
			}catch(Exception e){
				
			}
			
		}
        jTableEventosDoDia.setColumnSelectionAllowed(true);
        jScrollPane1.setViewportView(jTableEventosDoDia);

        jTableAniversarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Data", "Descrição"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableAniversarios.setColumnSelectionAllowed(true);
        Iterator<Contato> it2 = Agenda.Contatos.iterator();
        while (it2.hasNext()) {
			Contato Contato = it2.next();
			try{
				int mes = Integer.parseInt(Contato.getDataDeAniversario().substring(3, 5));
				if(mes == (calendar.get(GregorianCalendar.MONTH)+1)){
					DefaultTableModel modelo = (DefaultTableModel) jTableAniversarios.getModel();
					modelo.addRow(new String[]{Contato.getNome(),Contato.getDataDeAniversario(),Contato.getDescricao()});
				}
			}catch(Exception e){
				
			}
			
		}
        jScrollPane2.setViewportView(jTableAniversarios);

        BotaoPesquisaContatos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/search_user.png"))); // NOI18N
        BotaoPesquisaContatos.setToolTipText("Pesquisar contatos");
        BotaoPesquisaContatos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                final JFrame Pesquisa = new JFrame("Pesquisa Contatos");
                Pesquisa.setSize(300,140);
                Pesquisa.setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
                Pesquisa.setLocationRelativeTo(null); 
                JPanel painel = new JPanel();
                JLabel Nome = new JLabel("Digite o Nome:");
                final JTextField nome = new JTextField(20); 
                JButton Pesquisar = new JButton("Pesquisar");
                Pesquisar.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent arg0) {
						new PesquisaContatos(nome.getText()).setVisible(true);
						Pesquisa.setVisible(false);
						Pesquisa.dispose();
					}
                	
                });
                painel.add(Nome);painel.add(nome);painel.add(Pesquisar);
                Pesquisa.add(painel);
                Pesquisa.setVisible(true);
            }
        });

        BotaoPesquisaEvento.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/event_search_256.png"))); // NOI18N
        BotaoPesquisaEvento.setToolTipText("Pesquisa evento por nome");
        BotaoPesquisaEvento.addActionListener(new java.awt.event.ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				final JFrame Pesquisa = new JFrame("Pesquisa Evento");
                Pesquisa.setSize(300,140);
                Pesquisa.setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
                Pesquisa.setLocationRelativeTo(null); 
                JPanel painel = new JPanel();
                JLabel Nome = new JLabel("Digite o Nome:");
                final JTextField nome = new JTextField(20); 
                JButton Pesquisar = new JButton("Pesquisar");
                Pesquisar.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent arg0) {
						new JanelaPesquisaEventoNome(nome.getText()).setVisible(true);
						Pesquisa.setVisible(false);
						Pesquisa.dispose();
					}
                	
                });
                painel.add(Nome);painel.add(nome);painel.add(Pesquisar);
                Pesquisa.add(painel);
                Pesquisa.setVisible(true);
            }
        	
        });

        BotaoPesquisaEvento3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/event_icon_2011.png"))); // NOI18N
        BotaoPesquisaEvento3.setToolTipText("Pesquisa Evento por data");
        BotaoPesquisaEvento3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	final JFrame Pesquisa = new JFrame("Pesquisa Evento por data");
                Pesquisa.setSize(300,140);
                Pesquisa.setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
                Pesquisa.setLocationRelativeTo(null); 
                JPanel painel = new JPanel();
                JLabel Data = new JLabel("Digite a Data:");
                final JTextField data = new JTextField(20); 
                JButton Pesquisar = new JButton("Pesquisar");
                Pesquisar.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent arg0) {
						new JanelaPesquisaEventoData(data.getText()).setVisible(true);
						Pesquisa.setVisible(false);
						Pesquisa.dispose();
					}
                	
                });
                painel.add(data);painel.add(Data);painel.add(Pesquisar);
                Pesquisa.add(painel);
                Pesquisa.setVisible(true);   
            }
        });

        jLabel1.setFont(new java.awt.Font("Monotype Corsiva", 0, 36));
        jLabel1.setText("Aniversáriantes do Mês");
        jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jLabel2.setFont(new java.awt.Font("Monotype Corsiva", 0, 36));
        jLabel2.setText("Eventos do dia:");
        jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jLabelAnivérsarios.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/birthday.png"))); // NOI18N

        jLabelEventosDeHoje.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/today_icon.png"))); // NOI18N

        javax.swing.GroupLayout JPanelInicialLayout = new javax.swing.GroupLayout(JPanelInicial);
        JPanelInicial.setLayout(JPanelInicialLayout);
        JPanelInicialLayout.setHorizontalGroup(
            JPanelInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPanelInicialLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(BotaoPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BotaoContato, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BotaoCadastraContatos, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BotaoPesquisaContatos, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(CadastrarEventos, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ListaEventos, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BotaoPesquisaEvento, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BotaoPesquisaEvento3, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Sobre, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(272, 272, 272))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JPanelInicialLayout.createSequentialGroup()
                .addContainerGap(273, Short.MAX_VALUE)
                .addComponent(jLabelAnivérsarios)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addGap(392, 392, 392))
            .addGroup(JPanelInicialLayout.createSequentialGroup()
                .addGroup(JPanelInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(JPanelInicialLayout.createSequentialGroup()
                        .addGap(322, 322, 322)
                        .addComponent(jLabel3)
                        .addGap(106, 106, 106))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JPanelInicialLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabelEventosDeHoje)
                        .addGap(52, 52, 52)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addContainerGap(439, Short.MAX_VALUE))
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 1067, Short.MAX_VALUE)
            .addGroup(JPanelInicialLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JPanelInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 986, Short.MAX_VALUE))
                .addContainerGap(71, Short.MAX_VALUE))
        );
        JPanelInicialLayout.setVerticalGroup(
            JPanelInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPanelInicialLayout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addGroup(JPanelInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(BotaoPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BotaoCadastraContatos, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BotaoContato, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BotaoPesquisaContatos, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CadastrarEventos, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ListaEventos, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BotaoPesquisaEvento, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BotaoPesquisaEvento3, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Sobre, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(JPanelInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JPanelInicialLayout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabelEventosDeHoje)
                        .addGap(18, 18, 18))
                    .addGroup(JPanelInicialLayout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(jLabel2)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25)
                .addGroup(JPanelInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(JPanelInicialLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(37, 37, 37))
                    .addGroup(JPanelInicialLayout.createSequentialGroup()
                        .addComponent(jLabelAnivérsarios)
                        .addGap(18, 18, 18)))
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(JPanelInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 1044, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(33, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(JPanelInicial, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        
                                                                                  
    // Variables declaration - do not modify                     
    private javax.swing.JButton BotaoCadastraContatos;
    private javax.swing.JButton BotaoContato;
    private javax.swing.JButton BotaoPerfil;
    private javax.swing.JButton BotaoPesquisaContatos;
    private javax.swing.JButton BotaoPesquisaEvento;
    private javax.swing.JButton BotaoPesquisaEvento3;
    private javax.swing.JButton CadastrarEventos;
    private javax.swing.JPanel JPanelInicial;
    private javax.swing.JButton ListaEventos;
    private javax.swing.JButton Sobre;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelAnivérsarios;
    private javax.swing.JLabel jLabelEventosDeHoje;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTableAniversarios;
    private javax.swing.JTable jTableEventosDoDia;
    // End of variables declaration                   

}
